package com.eh.command.command.impl;

import com.eh.command.command.Command;
import com.eh.command.electric.CellingLight;
import com.eh.command.util.OperationHistoryUtil;

/**
 * Created by David on 2016/4/29.
 */
public class CellingLightCommand implements Command {

    private boolean flag;
    private boolean start;
    private CellingLight cellingLight;

    public CellingLightCommand(CellingLight cellingLight) {
        flag = false;
        start = true;
        this.cellingLight = cellingLight;
    }

    @Override
    public void execute() {
        if (start) {
            OperationHistoryUtil.record(cellingLight, "off");
            start = false;
        }
        if (!flag) {
            cellingLight.on();
            OperationHistoryUtil.record(cellingLight, "on");
        } else {
            cellingLight.off();
            OperationHistoryUtil.record(cellingLight, "off");
        }
        flag = !flag;
    }

    @Override
    public String toString() {
        return "吊灯控制器";
    }
}
